package com.prawn.ift.ctrlequipment.controller;

import com.prawn.ift.ctrlequipment.pojo.CtrlequipmentChannel;
import com.prawn.ift.ctrlequipment.service.CtrlEquipmentChannelService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import util.IdWorker;

import java.util.Date;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/12/13
 * @DESC： 控制设备通道管理
 */
@Controller
public class CtrlEquipmentChannelController {

    @Autowired
    private CtrlEquipmentChannelService ctrlEquipmentChannelService;
    @Autowired
    private IdWorker idWorker;

    /**
     * 添加控制设备通道信息
     * @Param ctrlEquipmentChannel
     * @return Result
     */
    @RequestMapping("/ctrlequipment/channel/add")
    @ResponseBody
    public Result add(CtrlequipmentChannel ctrlEquipmentChannel) {
        ctrlEquipmentChannel.setId(idWorker.nextId()+"");
        ctrlEquipmentChannel.setCreateDate(new Date());
        ctrlEquipmentChannel.setUpdateDate(new Date());
        return ctrlEquipmentChannelService.addCtrlEquipmentChannel(ctrlEquipmentChannel);
    }


    /**
     * 删除控制设备通道信息
     * @Param id
     * @return Result
     */
    @RequestMapping("/ctrlequipment/channel/delete")
    @ResponseBody
    public Result delete(String id) {
        return ctrlEquipmentChannelService.deleteCtrlEquipmentChannel(id);
    }

    /**
     * 修改控制设备通道信息
     * @Param ctrlEquipmentChannel
     * @return Result
     */
    @RequestMapping("/ctrlequipment/channel/edit")
    @ResponseBody
    public Result edit(CtrlequipmentChannel ctrlEquipmentChannel) {
        ctrlEquipmentChannel.setUpdateDate(new Date());
        return ctrlEquipmentChannelService.editCtrlEquipmentChannel(ctrlEquipmentChannel);
    }

    /**
     * 查询控制设备通道信息
     * @return CtrlequipmentChannel
     */
    @RequestMapping("/ctrlequipment/channel/{id}")
    @ResponseBody
    public CtrlequipmentChannel get(@PathVariable String id) {
        return ctrlEquipmentChannelService.getCtrlEquipmentChannelById(id);
    }

    /**
     * 查询控制设备通道信息列表
     * @return Result
     */
    @RequestMapping("/ctrlequipment/channel/list")
    @ResponseBody
    public Result getList() {
        return ctrlEquipmentChannelService.getCtrlEquipmentChannelList();
    }

    /**
     * 多条件控制设备通道信息列表
     * @return Result
     */
    @RequestMapping("/ctrlequipment/channel/queryByEquipmentId")
    @ResponseBody
    public Result getPage(String equipmentId) {
        return ctrlEquipmentChannelService.getCtrlEquipmentChannelListByEquipmentId(equipmentId);
    }

}
